<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ include file="/views/common/taglibs.jsp" %>
<!DOCTYPE>
<HTML>
<head>
    <!-- 引入通用js、css文件(xiaogq) -->
    <meta name="decorator" content="default"/>
    <link rel="stylesheet" type="text/css" href="${ctx}/css/common/operation/sys_operation.css"/>
    <link rel="stylesheet" type="text/css" href="${ctx}/css/system/organization/role/role_data.css"/>
</head>
<body>
    <input type="hidden" id="roleid" value="${roleid }"/>
    <div id="buttonArray" class="button_list">
        <%--<c:if test="${!isAdmin }">--%>
            <a href="javascript:;" id="resdSave">
                <span class="span_button">
                    <span><img src="${ctx}/image/common/operation/oper_SAVE.png"></span>
                    <span name="buTitle">保存</span>
                </span>
            </a>
        <%--</c:if>--%>
        <a href="javascript:;" onclick="javascript:parent.closeTab();">
            <span class="span_button">
                <span><img src="${ctx}/image/common/operation/oper_CANCEL.png"></span>
                <span name="buTitle" title="">取消</span>
            </span>
        </a>
        <a href="javascript:;" id="resdEnableAll">
            <span class="span_button">
                <span><img src="${ctx}/image/common/operation/oper_enableAll.png"></span>
                <span name="buTitle" title="">全部启用</span>
            </span>
        </a>
        <a href="javascript:;" id="resdDisableAll">
            <span class="span_button">
                <span><img src="${ctx}/image/common/operation/oper_disableAll.png"></span>
                <span name="buTitle" title="">全部停用</span>
            </span>
        </a>
    </div>

    <div class="content-wrap" style="padding:5px 0 10px 0.5%;width:99.5%;">
        <table class="table-report" cellpadding="0" cellspacing="0" style="width:65%;margin:0 0 10px 0;">
            <tr align="center" class="firstTh">
                <td width="20%">对象</td>
                <td width="20%">读取</td>
                <td width="20%">编辑</td>
                <td width="20%">删除</td>
                <td width="20%"></td>
            </tr>
            <c:if test="${not empty dataPmsList}">
                <c:forEach var="resd" items="${dataPmsList}" varStatus="v">
                    <c:if test="${v.index == 0 }">
                        <tr align="center" >
                            <td>&nbsp;</td>
                            <td>
                                <select name="level_view" class="filter-select" >
                                    <option value=""></option>
                                    <c:forEach var="scope" items="${dataScopeList}" varStatus="sv">
                                        <option value="${scope.name }">${scope.inChinese }</option>
                                    </c:forEach>
                                </select>
                            </td>
                            <td>
                                <select name="level_edit" class="filter-select" >
                                    <option value=""></option>
                                    <c:forEach var="scope" items="${dataScopeList}" varStatus="sv">
                                        <option value="${scope.name }">${scope.inChinese }</option>
                                    </c:forEach>
                                </select>
                            </td>
                            <td>
                                <select name="level_delete" class="filter-select" >
                                    <option value=""></option>
                                    <c:forEach var="scope" items="${dataScopeList}" varStatus="sv">
                                        <option value="${scope.name }">${scope.inChinese }</option>
                                    </c:forEach>
                                </select>
                            </td>
                            <td>&nbsp;</td>
                        </tr>
                    </c:if>
                    <tr eid="${resd.entityId }" changed="0" align="center"
                        <c:if test="${v.index%2 == 0}">class="tableOdd"</c:if>>
                        <td align="center">${resd.entityName }</td>
                        <td>
                            <select name="resdScope" stype="view_level" class="filter-select">
                                <c:forEach var="scope" items="${dataScopeList}" varStatus="sv">
                                    <option value="${scope.name }" <c:if test="${resd.viewLevel eq scope.name }">selected="selected"</c:if> >${scope.inChinese }</option>
                                </c:forEach>
                            </select>
                        </td>
                        <td>
                            <select name="resdScope" stype="edit_level" class="filter-select">
                                <c:forEach var="scope" items="${dataScopeList}" varStatus="sv">
                                    <option value="${scope.name }" <c:if test="${resd.editLevel eq scope.name }">selected="selected"</c:if> >${scope.inChinese }</option>
                                </c:forEach>
                            </select>
                        </td>
                        <td>
                            <select name="resdScope" stype="delete_level" class="filter-select">
                                <c:forEach var="scope" items="${dataScopeList}" varStatus="sv">
                                    <option value="${scope.name }" <c:if test="${resd.deleteLevel eq scope.name }">selected="selected"</c:if> >${scope.inChinese }</option>
                                </c:forEach>
                            </select>
                        </td>
                        <td>
                            <select name="all_level" class="filter-select">
                                <option value=""></option>
                                <c:forEach var="scope" items="${dataScopeList}" varStatus="sv">
                                    <option value="${scope.name }">${scope.inChinese }</option>
                                </c:forEach>
                            </select>
                        </td>
                    </tr>
                </c:forEach>
            </c:if>
        </table>
    </div>

    <script type="text/javascript">
        $(document).ready(function(){
            //保存
            $("#resdSave").bind("click",function(){
                var reddata = "";
                $("tr[changed='1']").each(function(){
                    var thisval =  $(this).attr("eid") + "=";
                    $(this).find("select[name='resdScope']").each(function(){
                        thisval = thisval + $(this).val() + "-";
                    });
                    reddata = reddata + thisval + "&";
                });

                if(reddata != ""){
                    $.ajax({
                        url: "${ctx}/"+Constants.updateRoleDataPmsUrl,
                        data: {
                            reddata : reddata,
                            roleid : $("#roleid").val()
                        },
                        type: 'POST',
                        success: function(data){
                            var flag = data.flag;
                            if(!flag){
                                alert("保存角色实体数据权限失败!");
                            }
                            parent.closeTab();
                        },
                        error: function() {
                            alert("保存角色实体数据权限错误!");
                        }
                    });
                }else{
                    parent.closeTab();
                }
            });

            $("select[name='resdScope']").bind("change",function(){
                $(this).parents("tr").attr("changed","1");
            });

            //全部启用
            $("#resdEnableAll").bind("click",function(){
                $("select[name='resdScope'] option:first-child").attr("selected",true);
                $("select[name='resdScope']").trigger("change");
            });

            //全部停用
            $("#resdDisableAll").bind("click",function(){
                $("select[name='resdScope'] option:last-child").attr("selected",true);
                $("select[name='resdScope']").trigger("change");
            });

            //快捷操作 - 纵向
            $("select[name^='level_']").bind("change",function(){
                var thisval = $(this).val();
                if(thisval != ""){
                    var thistype = $(this).attr("name").split("_")[1];
                    $("select[stype='"+thistype+"_level'] option[value='"+thisval+"']").attr("selected",true);
                    $("tr[changed]").attr("changed",'1');
                }
            });
            //快捷操作 - 横向
            $("select[name='all_level']").bind("change",function(){
                var thisval = $(this).val();
                if(thisval != ""){
                    $(this).parents("tr").find("select option[value='"+thisval+"']").attr("selected",true);
                    $(this).parents("tr").attr("changed","1");
                }
            });
        });
    </script>

</body>
</html>
